package Pages.sub;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.Sprite;

import Const.GConfig;
import Pages.Game;
import Pages.CPlayer;

public class Step {
	private int iX; // toa do x
	private int iY; // toa do y
	private int iTime; // thoi gian ve
	private int indexImg; // vi tri hinh
	private int iSee; // huong nhin
	private int xP; // x ve
	private int yP; // y ve
	private int iW; // do rong
	private int iH; // chieu cao

	public Step(int x, int y, int indexImg, int time, int iSee) {
		this.indexImg = indexImg;
		this.iTime = time;
		this.iSee = iSee;
		this.iX = x;
		this.iY = y;
		this.iW = CPlayer.imgStep.getWidth();
		this.iH = CPlayer.imgStep.getHeight() / 2;
		if (iSee == GConfig.k_iLeft || iSee == GConfig.k_iRight) {// ngang
			if (indexImg == 0) {
				xP = iX + 20;
				yP = iY + 10;
			} else {
				xP = iX + 20;
				yP = iY + 30;
			}
		} else {// doc
			if (indexImg == 0) {
				xP = iX + 30;
				yP = iY + 20;
			} else {
				xP = iX + 10;
				yP = iY + 20;
			}
		}
	}

	public void setStep(int x, int y, int indexImg, int time, int iSee) {
		this.indexImg = indexImg;
		this.iTime = time;
		this.iSee = iSee;
		this.iX = x;
		this.iY = y;
		if (iSee == GConfig.k_iLeft || iSee == GConfig.k_iRight) {// ngang
			if (indexImg == 0) {
				xP = iX + 20;
				yP = iY + 10;
			} else {
				xP = iX + 20;
				yP = iY + 30;
			}
		} else {// doc
			if (indexImg == 0) {
				xP = iX + 30;
				yP = iY + 20;
			} else {
				xP = iX + 10;
				yP = iY + 20;
			}
		}
	}

	public void paint(Graphics g) {
		if (iTime > 0) {
			switch (iSee) {
			case GConfig.k_iRight:
				g.drawRegion(CPlayer.imgStep, 0, indexImg * iH, iW, iH,
						Sprite.TRANS_NONE, xP + CPlayer.s_iMapX, yP
								+ CPlayer.s_iMapY, Graphics.HCENTER
								| Graphics.VCENTER);
				break;
			case GConfig.k_iLeft:
				g.drawRegion(CPlayer.imgStep, 0, indexImg * iH, iW, iH,
						Sprite.TRANS_MIRROR, xP + CPlayer.s_iMapX, yP
								+ CPlayer.s_iMapY, Graphics.HCENTER
								| Graphics.VCENTER);
				break;
			case GConfig.k_iDown:
				g.drawRegion(CPlayer.imgStep, 0, indexImg * iH, iW, iH,
						Sprite.TRANS_ROT90, xP + CPlayer.s_iMapX, yP
								+ CPlayer.s_iMapY, Graphics.HCENTER
								| Graphics.VCENTER);
				break;
			case GConfig.k_iUp:
				g.drawRegion(CPlayer.imgStep, 0, indexImg * iH, iW, iH,
						Sprite.TRANS_MIRROR_ROT90, xP + CPlayer.s_iMapX, yP
								+ CPlayer.s_iMapY, Graphics.HCENTER
								| Graphics.VCENTER);
				break;
			}
		}
	}

	public void update() {
		if (iTime > 0) {
			if (Game.timeTick % 10 == 0)
				iTime--;
			if (iSee == GConfig.k_iLeft || iSee == GConfig.k_iRight) {// ngang
				if (indexImg == 0) {
					xP = iX + 20;
					yP = iY + 10;
				} else {
					xP = iX + 20;
					yP = iY + 30;
				}
			} else {// doc
				if (indexImg == 0) {
					xP = iX + 30;
					yP = iY + 20;
				} else {
					xP = iX + 10;
					yP = iY + 20;
				}
			}
		}
	}

	public int getX() {
		return iX;
	}

	public int getIW() {
		return iW;
	}

	public void setIW(int iw) {
		iW = iw;
	}

	public int getIH() {
		return iH;
	}

	public void setIH(int ih) {
		iH = ih;
	}

	public int getISee() {
		return iSee;
	}

	public void setISee(int see) {
		iSee = see;
	}

	public void setX(int ix) {
		iX = ix;
	}

	public int getY() {
		return iY;
	}

	public void setY(int iy) {
		iY = iy;
	}

	public int getTime() {
		return iTime;
	}

	public void setTime(int time) {
		iTime = time;
	}

	public int getIndexImg() {
		return indexImg;
	}

	public void setIndexImg(int indexImg) {
		this.indexImg = indexImg;
	}
}
